package com.ftg.learn.day15.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 布衣
 */
public class FirstMybatis {

    public static void main(String[] args) {
        String path = "mybatis/configuration.xml";
        try {
            Reader reader = Resources.getResourceAsReader(path);

            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            SqlSessionFactory factory = builder.build(reader);
            SqlSession sqlSession = factory.openSession();

//            Map<String, Object> map = new HashMap<>();
//            map.put("a", 11);
//            map.put("b", "六千万人给");
//            map.put("c", "北京");

            Dept d = new Dept();
            d.setDeptno(12);
            d.setDname("软件测试");
            d.setLoc("中国北京");

            int num = sqlSession.insert("dept.saveDept", d);

            List<Map<String, Object>> list = sqlSession.selectList("dept.selDept");

            sqlSession.commit();
            reader.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }

}
